if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[FileStorage]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[FileStorage]
GO

if not exists (select * from master.dbo.syslogins where loginname = N'webuser')
BEGIN
	declare @logindb nvarchar(132), @loginlang nvarchar(132) select @logindb = N'master', @loginlang = N'us_english'
	if @logindb is null or not exists (select * from master.dbo.sysdatabases where name = @logindb)
		select @logindb = N'master'
	if @loginlang is null or (not exists (select * from master.dbo.syslanguages where name = @loginlang) and @loginlang <> N'us_english')
		select @loginlang = @@language
	exec sp_addlogin N'webuser', null, @logindb, @loginlang
END
GO

if not exists (select * from dbo.sysusers where name = N'webuser' and uid < 16382)
	EXEC sp_grantdbaccess N'webuser', N'webuser'
GO

CREATE TABLE [dbo].[FileStorage] (
	[FileStorageID] [int] IDENTITY (1, 1) NOT NULL ,
	[ContentLength] [int] NULL ,
	[FileName] [varchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
	[MimeType] [varchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
	[FileStream] [image] NULL 
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO

GRANT  SELECT ,  UPDATE ,  INSERT ,  DELETE  ON [dbo].[FileStorage]  TO [webuser]
GO

